package com.ryskoo.permission.dept.repository;

import com.ryskoo.framework.core.repository.BasicRedisImpl;
import com.ryskoo.framework.core.utils.RedisUtil;
import com.ryskoo.permission.dept.domain.DeptPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author Shawn
 */
@Primary
@Repository
public class DeptRedisImpl extends BasicRedisImpl<DeptPO> implements
		IDeptRepository {
	private static final String KEY_PRE = "PERMISSION_ROLE_";

	@Autowired
	private RedisUtil redisClient;

	@Autowired
	private IDeptRepository deptRepository;

	@PostConstruct
	public void init() {
		this.setRedisClient(redisClient);
		this.setDao(deptRepository);
	}

	public DeptRedisImpl() {
		super(KEY_PRE);
	}

	@Override
	public List<DeptPO> getByParentId(String parentId) {
		return deptRepository.getByParentId(parentId);
	}

	@Override
	public List<DeptPO> getDeptByParentIdAndSalesManId(String parentId, String salesManId) {
		return deptRepository.getDeptByParentIdAndSalesManId(parentId, salesManId);
	}
}
